package com.realone.packman.codec.decoder;

import com.realone.packman.codec.decoder.vo.BmsDecoderDataVoWarning;
import com.realone.packman.codec.exception.BmsDecoderException;

import java.nio.ByteBuffer;

/**
 * BMS 告警 应答解码
 *
 * @author hugx
 * @create 2018-09-17 11:16
 */
public class BmsDecoderWarning extends BmsDecoder<BmsDecoderDataVoWarning> implements BmsDecoderStrategy {

    public BmsDecoderWarning(Integer classType) {
       this.classType=classType;
    }

    @Override
    public BmsDecoderDataVoWarning decoderBody(ByteBuffer bb) {
        if (bb == null) {
            throw new BmsDecoderException(new NullPointerException());
        }

        BmsDecoderDataVoWarning result=new BmsDecoderDataVoWarning(super.classType);

        /*解析告警序号*/
        result.setSequenceNum(bb.getShort());

        /* 解析告警状态编码 */
        result.setStateCode(bb.get());

        /* 解析告警等级*/
        result.setLevel(bb.get());

        /* 解析告警定位 */
        result.setLoc(bb.get());

        /* 解析告警信息字段 */
        result.setInfo(bb.getInt() / 100.0);

        result.setTime(System.currentTimeMillis());

       return  result;
    }



}
